package com.leancloud.login.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.aries.ui.view.title.TitleBarView;
import com.leancloud.login.LoginPath;
import com.leancloud.login.R;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import tech.com.commoncore.base.BaseTitleActivity;
import tech.com.commoncore.utils.ApplicationUtil;

@Route(path = LoginPath.LOGIN_PRIVACY_AGREEMENT)
public class PrivacyAgreementActivity extends BaseTitleActivity {

    private TextView agreementTx;

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setLeftTextDrawable(R.mipmap.back_black)
                .setTitleMainText(getResources().getString(R.string.app_name) + "隐私协议")
                .setBgColor(Color.TRANSPARENT);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_privacy_agreement;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        agreementTx = findViewById(R.id.agreement_tx);

        String text = getFromAssets("PrivacyAgreement.html");
        text = text.replaceAll("招财黄金", ApplicationUtil.getAppName(mContext));
        agreementTx.setText(Html.fromHtml(text));
    }

    public String getFromAssets(String fileName) {
        try {
            InputStreamReader inputReader = new InputStreamReader(getResources().getAssets().open(fileName));
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line = "";
            String Result = "";
            while ((line = bufReader.readLine()) != null)
                Result += line;
            return Result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "解析错误";
    }
}
